﻿using Quartz;
using Volo.Abp.BackgroundWorkers.Quartz;

namespace LF.Application.Jobs
{
    public class OutReportJob : QuartzBackgroundWorkerBase, ILFJob
    {
        IScheduler? _scheduler;
        public OutReportJob()
        {
            JobDetail = JobBuilder.Create<OutReportJob>().WithIdentity(nameof(OutReportJob)).Build();
            SetTagger();
            ScheduleJob = async scheduler =>
            {
                _scheduler = scheduler;
                if (!await scheduler.CheckExists(JobDetail.Key))
                {
                    await scheduler.ScheduleJob(JobDetail, Trigger);
                }
            };
        }
        private void SetTagger()
        {
            Trigger = TriggerBuilder.Create()
             .WithCronSchedule("0 10 1 * * ? *")//每天执行0点
             .Build();
        }
        public void ChangeTrigger()
        {
            if (_scheduler == null) return;
            SetTagger();
            _scheduler.RescheduleJob(Trigger.Key, Trigger);
        }
        public override async Task Execute(IJobExecutionContext context)
        {
            //TODO
            await Task.CompletedTask;
        }
    }
}
